package serveletpackage;



import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyExample {
	
	
	

	private WebAppContext webAppContext;

	public static void main(String[] args) throws Exception
	{

		
		System.setProperty("org.eclipse.jetty.util.log.DEBUG","true"); 
		Server server = new Server(8080);
		ResourceHandler resource_handler = new ResourceHandler();
        resource_handler.setDirectoriesListed(true);
        resource_handler.setResourceBase(args.length == 2?args[1]:".");
        resource_handler.setWelcomeFiles(new String[]{ "index.html" });
        System.out.println("serving " + resource_handler.getBaseResource());
       
        ContextHandler context0 = new ContextHandler();
        context0.setContextPath("/senddata");
        Handler handler0=new HelloHandler();
        context0.setHandler(handler0);
       
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[]{context0});
        
        HandlerCollection handlersc = new HandlerCollection();
        handlersc.setHandlers(new Handler[]{resource_handler, contexts});
        server.setHandler(handlersc);
 
//        server.setHandler(new HelloHandler());
		server.start();
		server.join();

	}

}
